package com.angel.activity;

import java.util.HashMap;

import org.json.JSONException;
import org.json.JSONObject;

import com.angel.entity.Task;
import com.angel.port.IActivity;
import com.angel.util.BaseUtil;
import com.angel.util.StringUtil;
import com.angel.util.UserInfoUtil;
import com.umeng.analytics.MobclickAgent;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class FeekBack extends Activity implements IActivity{
        private EditText feedBackEdit;//反馈编辑框
        private TextView titleTxt;//设置标题
        private Context context;
        private ProgressDialog progressDialog;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		 MobclickAgent.onError(this);//自动捕获异常退出（FC ）
		setContentView(R.layout.feek_back);
		context=FeekBack.this;
		progressDialog=new ProgressDialog(context);
		progressDialog.setMessage("提交中...");
		context=FeekBack.this;
		feedBackEdit=(EditText)findViewById(R.id.feek_back_text);
		titleTxt=(TextView)findViewById(R.id.top_bar_title_txt_id);
		titleTxt.setText(getResources().getString(R.string.feek_back_title));
	}
	//返回按钮事件
	public void share_back(View v){
		finish();
	}
	//提交反馈按钮事件
	public void show_sharedialog(View v){
		HashMap<String,String> map=new HashMap<String,String>();
		String text=feedBackEdit.getText().toString();
		if(StringUtil.isBlank(text)){//判断是否为空
			BaseUtil.makeToast(this, "请填写您的意愿");
			return ;
		}
		map.put("feekBack", text);
		map.put("userId",UserInfoUtil.getValue(context, "userId", "0"));
		BaseUtil.startService(Task.FEEKBACK_ACTIVITY, this, map);
		progressDialog.show();
	}
	@Override
	public void init() {
	}
	@Override
	public void refresh(Object... params) {
		    String isSucess=BaseUtil.getValueFromJSON((String)params[0]);
			    if(isSucess.equals("2")){
				 BaseUtil.makeToast(FeekBack.this, "对不起,网络连接超时,请稍后重试...");
				 progressDialog.dismiss();
				 return ;
		    }
			if(isSucess.equals("1")){
				BaseUtil.makeToast(this, "感谢您的意见反馈");
			}else{
				BaseUtil.makeToast(this, "sorry,服务器出错，请稍后再试");
			}
			progressDialog.dismiss();
	}
	@Override
	protected void onResume() {
	super.onResume();
	 MobclickAgent.onResume(this);
	}
	@Override
	protected void onPause() {
	super.onPause();
	 MobclickAgent.onPause(this);
	
	}
}
